<template>
  <el-form :rules="rules" ref="ruleForm" :model="form" label-width="80px">
    <el-form-item label="锁名称" prop="name">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit('ruleForm')">立即创建</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      form: {
        name: ''
      },
      ruleForm: {
        name: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入锁名', trigger: 'blur' }
        ],
      }
    }
  },
  methods: {
    onSubmit(ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          axios.post('/lock/save', this.form).then( resp => {
            if (resp.data == 'success') {
              // this.$message.success('添加成功')
              this.$alert('添加成功', '消息', {
                confirmButtonText: '确定',
                callback: action => {
                  this.$router.push("/page1")
                }
              })
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
}
</script>

<style scoped>

</style>